package characterCreator;

import java.util.Random;

public class Fighter extends Character{
	private int[] expTable = 	{ 0,0,2000,4000,8000,16000,32000,64000,120000,240000,
	                          	360000,480000,600000,720000,840000,960000,1080000,
	                          	1200000,1320000,1440000,1560000,1680000,1800000,
	                          	1920000,2040000,2160000,2280000,2400000,2520000,
	                          	2640000,2760000,2880000,3000000,3120000,3240000,
	                          	3360000,3480000 };
	
	private int[] toHitTable = { 20,19,19,19,17,17,17,15,15,15,13,13,13,11,11,11,
								9,9,9,7,7,7,5,5,5,3,3,3,2,2,2,2,2,2,1,1,1 };
	
	private int[] svPoison = 	{ 14,12,12,12,10,10,10,8,8,8,6,6,6,6,6,6,5,5,5,5,5,5,
								4,4,4,4,4,4,3,3,3,3,3,3,2,2,2 };
	
	private int[] svMagicWand = { 15,13,13,13,11,11,11,9,9,9,7,7,7,6,6,6,6,6,6,5,5,5,
								5,5,5,4,4,4,4,4,4,3,3,3,2,2,2 };
	
	private int[] svParalysis = { 16,14,14,14,12,12,12,10,10,10,8,8,8,7,7,7,6,6,6,6,6,6,
								5,5,5,5,5,5,4,4,4,3,3,3,2,2,2 };
	
	private int[] svDragon = 	{ 17,15,15,15,13,13,13,11,11,11,9,9,9,8,8,8,7,7,7,6,6,6,
								5,5,5,4,4,4,3,3,3,2,2,2,2,2,2 };
	
	private int[] svSpell = 	{ 17,16,16,16,14,14,14,12,12,12,10,10,10,9,9,9,8,8,8,7,7,7,
								6,6,6,5,5,5,4,4,4,3,3,3,2,2,2 };
	
	public Fighter() {
		this.setType(ClassType.Fighter);
		
		for (Abilities a : Abilities.values()) {
			this.setAbility(a, 0);
		}
		
		this.setPrimeRequisite(Abilities.Strength, 0);
		this.setLevel(0);
		this.setAC(10);
	}
	
	public Fighter(Character currentCharacter) {
		this.setType(ClassType.Fighter);
		
		this.setName(currentCharacter.getName());
		this.setPlayer(currentCharacter.getPlayer());
		this.setSex(currentCharacter.getSex());
		this.setAlignment(currentCharacter.getAlignment());
		
		for (Abilities a : Abilities.values()) {
			this.setAbility(a, currentCharacter.getAbility(a));
		}
		
		this.setPrimeRequisite(Abilities.Strength, 0);
		this.setLevel(currentCharacter.getLevel());
		this.setAC(currentCharacter.getAC());
	}
	
	public void setLevel(int level) {
		
		Random random = new Random(System.currentTimeMillis());
		
		this.level = level;

		System.out.println("level was set to " + level);
		
		if (level <= 9) {
			this.setHP(new Die().Roll(level, 8));
		} else {
			this.setHP((new Die().Roll(9, 8)+2*level));
		}
		
		this.setExp(expTable[level]);
		
		this.setExpBonus();
		
		System.out.println("EXP: " + this.getExp());
		
		this.setTHAC0(toHitTable[level]);
		
		for (SavingThrow a : SavingThrow.values()) {
			this.setSave(a, getSaveTable(a)[level]);
		}
	}
	
	public int[] getSaveTable(SavingThrow a) {
		switch (a) {
		case svPoison:
			return svPoison;
		case svMagicWand:
			return svMagicWand;
		case svParalysis:
			return svParalysis;
		case svDragon:
			return svDragon;
		case svSpell:
			return svSpell;
		}
		return null;
	}
}
 